<div class="content-box"><!-- start_chungloai Content Box -->
    <div class="content-box-header">
        <h3>Quản lý danh mục sản phẩm</h3>
        <ul class="content-box-tabs">
            <li><a href="#tab1" class="default-tab">Table</a></li> <!-- href must be unique and match the id of target div -->
            <li><a href="#tab2">Forms</a></li>
        </ul>
        <div class="clear"></div>
    </div> <!-- End .content-box-header -->
    <div class="content-box-content">
        <div class="tab-content default-tab" id="tab1">
        	<?php
$sql=mysql_query("SELECT * FROM `tbl_danhmuc` WHERE `id`='".$id."'");
$row=mysql_fetch_array($sql);
$hide_show=1;
$txt_madanhmuc='';$txt_tendanhmuc='';$anhdm='';$anh='';
if(isset($_POST['txt_madanhmuc']))	
	{
		$txt_madanhmuc=$_POST['txt_madanhmuc'];
		$hide_show=0;
	}
	if(isset($_POST['txt_tendanhmuc']))	$txt_tendanhmuc=$_POST['txt_tendanhmuc'];
	
	if($hide_show==1)
	{
?>
    <form  name="frnn" action="" method="post" enctype="multipart/form-data">
        
        <table>
            <tr>
                <td>Ảnh danh mục</td>
                <td><input type="file" name="txt_anhdm" id="txt_anhdm" /></td>
            </tr>
            <tr>
            	<td>Tên danh mục</td>
                <td><input type="text" name="txt_tendanhmuc" placeholder="Tên danh mục" style="width:300px;height:15px" value="<?php echo $row['danhmuc']?>"></td>
            </tr>
 			<tr>
            	<td>Mã danh mục</td>
                <td><input name="txt_madanhmuc" type="text" placeholder="Mã danh mục" style="width: 300px;height:15px" value="<?php echo $row['danhmuc_id']?>" ></td>
            </tr>
            <tr>
            	<td><input type="reset" value="Nhập lại" name="btn_reset" style="width: 100px"/></td>
                <td><input class="button" type="submit" value="Sửa" name="sua" style="width: 100px"/></td>
            </tr>
       	</table>
    </form>
    <?php
	}else
	{
    //Define some variables
    $dir = "uploads/"; //Bạn nên thay đổi đường dẫn cho phù hợp
    //Kiều file, Gif, jpeg, zip ::bạn có thể sửa đổi nếu thích
    $types = array("image/gif","image/GIF","image/JPG","image/PNG","image/png","image/jpg","image/JPEG","image/jpeg","application/x-zip-compressed","application/msword","application/vnd.ms-excel");
    //Check to determine if the submit button has been pressed
    if(isset($_POST["sua"])){
        //Shorten Variables
        $tmp_name = $_FILES["txt_anhdm"]["tmp_name"];
        $new_name = $_FILES["txt_anhdm"]["name"];
        //Check MIME Type
        if (in_array($_FILES["txt_anhdm"]["type"], $types)){
            //Move file from tmp dir to new location
            move_uploaded_file($tmp_name,'../'.$dir.$new_name);
            $txt_anhdm=$new_name;
            echo "<script>alert('File {$_FILES["txt_anhdm"]["name"]} đã gửi xong!');</script>";
        }else{
            //Print Error Message
            echo "<script>alert('{$_FILES["txt_anhdm"]["name"]} upload file thất bại !');</script>";
            //Debug
            $name =  $_FILES["txt_anhdm"]["name"];
            $type =  $_FILES["txt_anhdm"]["type"];
            $size =  $_FILES["txt_anhdm"]["size"];
            $tmp  =  $_FILES["txt_anhdm"]["name"];
            echo "Name: $name<br/ >Type: $type<br />Size: $size<br />Tmp: $tmp";
        }
    }
    else{
        echo 'Không có file upload';
    }
		$sqli31="UPDATE `tbl_danhmuc` SET `danhmuc`='".$txt_tendanhmuc."',`anhdm`='".$txt_anhdm."',`danhmuc_id`='".$txt_madanhmuc."' WHERE `id`='".$id."'";
		$sql3_1=mysql_query($sqli31);
		if(isset($sql3_1))
		{
			?>
            <script>alert('Sửa Thành Công ! ');</script>
            <?php
			header("refresh:1; index.php?page=danhmuc");
		}else
		{
			?>
            <script>alert('Sửa Thất bại ! ');</script>
            <?php
			header("refresh:1; index.php?page=danhmuc&act=edit&edit=".$id);
		}
	}
	?>
        </div> <!-- End #tab1 -->
    </div> <!-- End .content-box-content -->
</div> <!-- End .content-box -->
